import request from '@/utils/request';
import { download, toFormData, checkDownloadRes } from '@/utils/common';

/**
 * 分页查询库存查询
 */
export async function pageMesInventoryQuerys(params) {
  const res = await request.get('/mes/mesInventoryQuery/list', { params });
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 查询全部库存查询
 */
export async function listMesInventoryQuerys(params) {
  const res = await request.get('/mes/mesInventoryQuery/list', { params });
  if (res.data.code === 200) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 根据id查询库存查询
 */
export async function getMesInventoryQuery(id) {
  const res = await request.get('/mes/mesInventoryQuery/' + id);
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 添加库存查询
 */
export async function addMesInventoryQuery(data) {
  const res = await request.post('/mes/mesInventoryQuery', data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 修改库存查询
 */
export async function updateMesInventoryQuery(data) {
  const res = await request.put('/mes/mesInventoryQuery', data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 删除库存查询
 */
export async function removeMesInventoryQuery(id) {
  const res = await request.delete('/mes/mesInventoryQuery/' + id);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 批量删除库存查询
 */
export async function removeMesInventoryQuerys(ids) {
  const res = await request.delete('/mes/mesInventoryQuery/' + ids.join());
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 导出库存查询
 */
export async function exportMesInventoryQuerys(params) {
  const res = await request({
    url: '/mes/mesInventoryQuery/export',
    method: 'POST',
    data: toFormData(params),
    responseType: 'blob'
  });
  await checkDownloadRes(res);
  download(res.data, `mesInventoryQuery_${Date.now()}.xlsx`);
}
